#include "Mask.h"
#include "../utils/CoordinateUtil.h"

int Mask::mCount = 0;
Mask::Mask()
	:mTarget(NULL),mSelector(NULL)
{
}


Mask::~Mask(void)
{
	
}

Mask * Mask::create( float opacity )
{
	Mask * pLayer = new Mask();
    pLayer->init();
	ccColor4B color = ccc4(0, 0, 0, opacity);
    pLayer->initWithColor(color);
	pLayer->setTouchEnabled(false);
	return pLayer;
}

bool Mask::init()
{
	return true;
}

void Mask::onEnter()
{
	CCLayer::onEnter();
	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority, true);
	
}

void Mask::onExit()
{
	CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
	CCLayer::onExit();
}

bool Mask::ccTouchBegan( CCTouch *pTouch, CCEvent *pEvent )
{
	activate();
	return true;		
}

void Mask::ccTouchMoved( CCTouch *pTouch, CCEvent *pEvent )
{

}

void Mask::ccTouchEnded( CCTouch *pTouch, CCEvent *pEvent )
{

}

void Mask::ccTouchCancelled( CCTouch *pTouch, CCEvent *pEvent )
{

}

void Mask::setTarget( CCObject *target, SEL_CallFunc selector )
{
	mTarget = target;
	mSelector = selector;
}

void Mask::activate()
{
	if (mTarget != NULL && mSelector != NULL)
	{
		(mTarget->*mSelector)();
	}
}
